package com.webdev.newtech.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.webdev.newtech.domain.FriendDynamics;
import com.webdev.newtech.mapper.IFriendDynamicsMapper;
import com.webdev.newtech.service.IFriendDynamicsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

//纳入Spring管理
@Service
public class FriendDynamicsServiceImpl implements IFriendDynamicsService {

    //获取到操作数据库表的实例
    @Autowired
    IFriendDynamicsMapper dynamicsMapper;

    @Override
    public int add(FriendDynamics dynamics) {
        dynamics.setPublishTime(new Date());
        return dynamicsMapper.insert(dynamics);
    }

    @Override
    public int remove(Integer id) {
        return dynamicsMapper.deleteById(id);
    }

    @Override
    public int update(FriendDynamics dynamics) {
        return dynamicsMapper.updateById(dynamics);
    }

    @Override
    public List<FriendDynamics> getList(FriendDynamics dynamics) {
        QueryWrapper<FriendDynamics> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("publish_time");
        return dynamicsMapper.selectList(wrapper);
    }

    @Override
    public FriendDynamics getById(Integer id) {
        return dynamicsMapper.selectById(id);
    }
}
